﻿using System;
using System.ComponentModel.DataAnnotations;
using MSAcademic.v2.Infrastructure.Login;
using MSAcademic.v2.Infrastructure.User;

namespace MSAcademic.v2.Web.Areas.Admin.Models.User
{
    public partial class UserUpdateViewModel
    {
        public int Id { get; set; }
        [Required(ErrorMessage = "Polje ne smije biti prazno")]
        public string Username { get; set; }

        public string Password { get; set; }

        [Compare("Password", ErrorMessage = "Lozinke se moraju podudarati")]
        public string ConfirmPassword { get; set; }

        [Required(ErrorMessage = "Polje ne smije biti prazno")]
        public string FirstName { get; set; }

        [Required(ErrorMessage = "Polje ne smije biti prazno")]
        public string LastName { get; set; }
        public string Description { get; set; }

        [Required(ErrorMessage = "Polje ne smije biti prazno"), EmailAddress]
        public string Email { get; set; }


        public string FacebookLink { get; set; }
        public string TwitterLink { get; set; }
        public string LinkedInLink { get; set; }
        public string OtherLink { get; set; }

        public string ErrorMessage { get; set; }
    }
    public partial class UserUpdateViewModel
    {
        public IUser SignedInUser
        {
            get
            {
                if (_signedInUser == null)
                {
                    _signedInUser = new Lazy<IUser>(() => _loginService.TryGetSignedInUser());
                }
                return _signedInUser.Value;
            }
        }
        private Lazy<IUser> _signedInUser;
        public IUser User
        {
            get
            {
                if (_user == null)
                {
                    _user = new Lazy<IUser>(() => _userQueries.TryGetWhereId(Id));
                }
                return _user.Value;
            }
        }
        private Lazy<IUser> _user;
        public bool IsUsernameValid
        {
            get
            {
                if (_isUsernameValid == null)
                {
                    _isUsernameValid = new Lazy<bool>(() => _userQueries.TryGetWhereUsername(Username) == null);
                }
                return _isUsernameValid.Value;
            }
        }
        private Lazy<bool> _isUsernameValid;
    }
    public partial class UserUpdateViewModel
    {
        private readonly IUserQueries _userQueries;
        private readonly ILoginService _loginService;
        public UserUpdateViewModel(IUserQueries userQueries, ILoginService loginService)
        {
            _userQueries = userQueries;
            _loginService = loginService;
        }
    }
}